<template>
  <div class="blog-page" @keydown="handleKeydown" tabindex="0" ref="pageRef">
    <!-- 彩蛋提示 -->
    <div class="easter-egg-hint" :class="{ show: showEasterEgg }">
      <div class="hint-content">
        <span class="hint-icon">🎮</span>
        <span class="hint-text">试试按 ← 键返回上一页</span>
      </div>
    </div>

    <!-- 联系信息卡片 -->
    <div class="contact-hero">
      <div class="hero-content">
        <div class="hero-text">
          <h1 class="hero-title">Let's Connect</h1>
          <p class="hero-subtitle">如果您有任何问题或合作意向，欢迎随时联系我</p>
        </div>
        <div class="hero-decoration">
          <div class="decoration-circle"></div>
          <div class="decoration-line"></div>
        </div>
      </div>
    </div>

    <!-- 主要联系方式 -->
    <div class="contact-methods">
      <div class="method-card" @click="handleContactClick('email')">
        <div class="method-icon">📧</div>
        <div class="method-content">
          <h3>Email</h3>
          <p>{{ contactData.email }}</p>
          <span class="method-desc">最快回复方式</span>
        </div>
      </div>

      <div class="method-card" @click="handleContactClick('github')">
        <div class="method-icon">🐙</div>
        <div class="method-content">
          <h3>GitHub</h3>
          <p>{{ contactData.github }}</p>
          <span class="method-desc">开源项目合作</span>
        </div>
      </div>

      <a-popover trigger="click" placement="top" :content="wechatPopoverContent" overlayClassName="wechat-popover">
        <div class="method-card" style="cursor: pointer">
          <div class="method-icon">📱</div>
          <div class="method-content">
            <h3>WeChat</h3>
            <p>{{ contactData.wechat }}</p>
            <span class="method-desc">扫码添加好友</span>
          </div>
        </div>
      </a-popover>
    </div>

    <!-- 合作领域 -->
    <div class="collaboration-section">
      <h2 class="section-title">合作领域</h2>
      <div class="collaboration-grid">
        <div class="collab-item" v-for="area in collaborationAreas" :key="area.title">
          <div class="collab-icon">{{ area.icon }}</div>
          <h3>{{ area.title }}</h3>
          <p>{{ area.description }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted, h, computed, nextTick } from 'vue';
  import { useRouter } from 'vue-router';
  import { useBlogConfig } from '/@/hooks/blog/useBlogConfig';

  // 组件名多词化
  // @ts-ignore
  defineOptions({ name: 'BlogContactPage' });

  const router = useRouter();
  const pageRef = ref<HTMLElement>();
  const showEasterEgg = ref(false);

  // 使用博客配置
  const { getContactData, loadAllConfigs } = useBlogConfig();
  const contactData = getContactData;

  // 合作领域类型定义
  interface CollaborationArea {
    icon: string;
    title: string;
    description: string;
  }

  // 计算属性：确保collaborationAreas是数组类型
  const collaborationAreas = computed<CollaborationArea[]>(() => {
    const areas = contactData.value.collaborationAreas;
    if (Array.isArray(areas)) {
      return areas;
    }
    // 如果areas是字符串，尝试解析JSON
    if (typeof areas === 'string') {
      try {
        return JSON.parse(areas);
      } catch {
        return [];
      }
    }
    return [];
  });

  const wechatPopoverContent = h('div', { style: 'text-align:center;' }, [
    h('img', {
      src: contactData.value.wechatQr,
      alt: '微信二维码',
      style: 'max-width:200px;height:auto;border-radius:8px;display:block;margin:0 auto 8px auto;',
    }),
    h('div', { style: 'color:#666;font-size:1rem;margin-top:4px;' }),
  ]);

  const handleKeydown = (event: KeyboardEvent) => {
    if (event.key === 'ArrowLeft') {
      goBack();
    }
  };

  const goBack = () => {
    router.go(-1);
  };

  const handleContactClick = (type: string) => {
    switch (type) {
      case 'email':
        window.open(`mailto:${contactData.value.email}`, '_blank');
        break;
      case 'github':
        window.open(`https://github.com/${contactData.value.github}`, '_blank');
        break;
    }
  };

  onMounted(async () => {
    // 加载配置数据
    await loadAllConfigs();

    // 设置页面焦点，确保键盘事件能够正确触发
    nextTick(() => {
    if (pageRef.value) {
      pageRef.value.focus();
    }
    });
    
    setTimeout(() => {
      showEasterEgg.value = true;
      setTimeout(() => {
        showEasterEgg.value = false;
      }, 3000);
    }, 2000);
  });
</script>

<style scoped>
  .blog-page {
    padding: 2rem 0;
    position: relative;
    outline: none;
  }

  /* 彩蛋提示 */
  .easter-egg-hint {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(24, 144, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 12px 16px;
    color: white;
    font-size: 0.9rem;
    z-index: 1000;
    transform: translateX(100%);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(24, 144, 255, 0.3);
  }

  .easter-egg-hint.show {
    transform: translateX(0);
  }

  .hint-content {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .hint-icon {
    font-size: 1.2rem;
    animation: bounce 2s infinite;
  }

  .hint-text {
    font-weight: 500;
  }

  /* 联系英雄区域 */
  .contact-hero {
    margin-bottom: 3rem;
  }

  .hero-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3rem;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  }

  .hero-text {
    flex: 1;
  }

  .hero-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: white;
    margin: 0 0 1rem 0;
    background: linear-gradient(135deg, #1890ff 0%, #52c41a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .hero-subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
    line-height: 1.6;
  }

  .hero-decoration {
    position: relative;
    width: 120px;
    height: 120px;
  }

  .decoration-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    border: 2px solid rgba(24, 144, 255, 0.3);
    border-radius: 50%;
    animation: rotate 10s linear infinite;
  }

  .decoration-line {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #1890ff, transparent);
    border-radius: 1px;
  }

  /* 联系方式 */
  .contact-methods {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 4rem;
  }

  .method-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(15px);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
  }

  .method-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    border-color: rgba(24, 144, 255, 0.3);
  }

  .method-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
  }

  .method-content h3 {
    color: white;
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
  }

  .method-content p {
    color: #1890ff;
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0 0 0.5rem 0;
  }

  .method-desc {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
  }

  /* 合作领域 */
  .collaboration-section {
    margin-bottom: 3rem;
  }

  .section-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 3rem;
  }

  .collaboration-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
  }

  .collab-item {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(15px);
    border-radius: 16px;
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    transition: all 0.3s ease;
  }

  .collab-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    border-color: rgba(24, 144, 255, 0.3);
  }

  .collab-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
  }

  .collab-item h3 {
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
  }

  .collab-item p {
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
    line-height: 1.5;
  }

  /* 动画 */
  @keyframes rotate {
    from {
      transform: translate(-50%, -50%) rotate(0deg);
    }
    to {
      transform: translate(-50%, -50%) rotate(360deg);
    }
  }

  @keyframes bounce {
    0%,
    20%,
    50%,
    80%,
    100% {
      transform: translateY(0);
    }
    40% {
      transform: translateY(-8px);
    }
    60% {
      transform: translateY(-4px);
    }
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .hero-content {
      flex-direction: column;
      text-align: center;
      gap: 2rem;
      padding: 2rem;
    }

    .hero-title {
      font-size: 2rem;
    }

    .contact-methods {
      grid-template-columns: 1fr;
    }

    .collaboration-grid {
      grid-template-columns: 1fr;
    }

    .easter-egg-hint {
      top: 10px;
      right: 10px;
      font-size: 0.8rem;
      padding: 10px 12px;
    }
  }
</style>
 